// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async remoteInfo() {
    //
  },

  // —————————————————————————————— 列表 —————————————————————————————— //

  async remoteList({ state: { API, param, MAP } }) {
    const TIP = API.transTip(MAP.tipList)
    const [num, arr] = await API.getList(param, TIP)
    return [num, transList(arr)]
  },

  // —————————————————————————————— 下载 —————————————————————————————— //

  async remoteDownload({ state: { API, param, downParam, MAP, refTable, sub } }) {
    const TIP = API.transTip(MAP.tipList)
    const SUB_TIP = sub ? API.transTip(sub.MAP.tipList) : ''

    const multi = [
      API.getList({ ...param, ...downParam }, TIP), // 表一
      sub ? sub.API.getList({ ...sub.param, ...downParam }, SUB_TIP) : [0, []], // 表二
    ]

    const [[, arr1], [, arr2]] = await Promise.all(multi)

    const { titleList: headers = [], arrayList: lists = [] } = refTable.getData(arr1)
    const { titleList: secondHeaders = [], arrayList: secondLists = [[]] } = sub ? sub.refTable.getData(arr2) : {}

    const msg = await API.download({ ...downParam, headers, lists, secondHeaders, secondLists }, `导出${MAP.WORD}`)
    return msg
  },
}

// ============================== 转换方法 ============================== //

const transList = (arr) => {
  return arr
}
